<?php
	//$server = new swoole_server("127.0.0.1", 9502);
	//$server->set(array('task_worker_num' => 4));
	//$server->on('receive', function($server, $fd, $reactor_id, $data) {
	//	$task_id = $server->task("Async");
	//	echo "Dispath AsyncTask: [id=$task_id]\n";
	//});
	//$server->on('task', function ($server, $task_id, $reactor_id, $data) {
	//	echo "New AsyncTask[id=$task_id]\n";
	//	$server->finish("$data -> OK");
	//});
	//$server->on('finish', function ($server, $task_id, $data) {
	//	echo "AsyncTask[$task_id] finished: {$data}\n";
	//});
	//
	//$server->on('WorkerStart', function($server) {
	//	$server->tick(3000, function() use($server){
	//		$server->task('haha');
	//	});
	//});
	//$server->start();
	
	$process = new swoole_process('callback_function', true);
	
	$pid = $process->start();
	
	function callback_function () {
		echo "hello world";
	};
	
	swoole_timer_tick(1000, function () {
		echo "parent timer\n";
	});
	
	swoole_process::signal(SIGCHLD, function ($sig) {
		while ($ret = Swoole\Process::wait(false)) {
			 // create a new child process
			$p = new Swoole\Process('callback_function');
			$p->start();
		}
	});
	
	// create a new child process
	$p = new Swoole\Process('callback_function');

	swoole_event_add($p->pipe, function ($pipe) use ($p) {
		echo $p->read();
	});

	$p->start();
